/*
  路由配置对象的的属性如下
   path:路由的路径，用户通过地址来访问路由中的组件
   component:组件
*/
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Vue from 'vue'
export default [
    {
        path: '',
        redirect: '/login'
    },

    {
        path: '/login',
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/register',
        component: () => import('@/views/Register.vue')
    },
    {
        path: '/home',
        component: () => import('@/views/Home.vue'),
        // beforeEnter: async function (to, from, next) {
        //     const token = localStorage.getItem('token')
        //     if (token) {
        //         try {
        //             await Vue.prototype.$api.users.getUserInfoApi()
        //             next()
        //         } catch (error) {
        //             localStorage.removeItem('token')
        //             next('/login')
        //         }
        //     } else {
        //         NProgress.done()//在路由守卫中，如果自己另外指定转发，就需要手动关闭Nprogress
        //         next('/login')
        //     }
        // },
        children: [
            {
                path: '',
                redirect: 'dashbaord'
            },
            {
                path: 'dashbaord',
                component: () => import('@/views/Dashboard.vue'),
                meta: {
                    isKeepAlive: true,
                    title: '主页'
                }
            },
            {
                path: 'users',
                component: () => import('@/views/User.vue'),
                meta: {
                    isKeepAlive: true,
                    breadcrumbList: ['系统管理', '用户管理']
                }
            },
            {
                path: 'director',
                component: () => import('@/views/Director.vue'),
                meta: {
                    isKeepAlive: false,
                    breadcrumbList: ['教学管理', '班主任管理']
                }
            },
            {
                path: 'students',
                component: () => import('@/views/Students.vue'),
                meta: {
                    isKeepAlive: true,
                    breadcrumbList: ['教学管理', '学生管理']
                }
            },
            {
                path: 'teacher',
                component: () => import('@/views/Teacher.vue'),
                meta: {
                    isKeepAlive: true,
                    breadcrumbList: ['教学管理', '教师管理']
                }
            },
            {
                name: 'sxxq',
                path: 'studentdetail',
                props: function (route) {
                    return {
                        id: route.query.id
                    }
                },
                meta: {
                    isKeepAlive: true
                },
                component: () => import('@/views/StudentDetail.vue')
            },
            {
                name: 'sxxg',
                path: 'studentModify/:sid/:sname',
                props: true,
                meta: {
                    isKeepAlive: true
                },
                component: () => import('@/views/StudentModify.vue')
            }
        ]
    },
    {
        path: '*',
        redirect: '/404'
    },
    {
        path: '/404',
        component: () => import('@/views/NotFound.vue')
    },
]